<?php
/**
 * Created by PhpStorm.
 * User: Tsang
 * Date: 2017/9/24 16:20
 *
 */

namespace app\api\model;

use think\Model;

class Task extends Model
{
    protected $type = [
        'created_at' =>  'timestamp:Y-m-d H:i:s',
        'end_time'   =>  'timestamp:Y-m-d H:i:s',
    ];

    /**
     * 获取团队
     * @param $original
     * @return mixed
     */
    public function getAll($where='',$page,$order='')
    {
        $input = input();
        $orderRule = empty($order) ? ['id'=>'desc'] : $order;
        $task = $this->where($where)->order($orderRule)->limit($page)->select();
        foreach ($task as $key => $value) {
            $status = 0;
            $where1['uid'] = ['=',$input['uid']];
            $where1['task_id'] = ['=',$value['id']];
            $where1['created_at'] = ['between',[strtotime(date('Y-m-d 00:00:00')),strtotime(date('Y-m-d 23:59:59'))]];
            $data = db('task_record')->where($where1)->find();
            if ($data) {
                $status = 1;//1进行中不可领取  0失效可领取
            }
            $task[$key]['status'] = $status;
            $arr = explode(',',$value['task_picture_url']);
            $task[$key]['task_picture_url'] = $arr;
        }
        return $task;
    }

}